<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="js/jquery-3.6.0.js"></script>

    </head>
    <body>
        请输入 userId 的值<input type="text" id="userId" />
        <br/>
        请输入 classId 的值<input type="text" id="classId" />
        <br/>
        <button id="submit">以POST的方式提交JSON格式数据</button>
    </body>
    <script>
        let userIdInput = document.querySelector("#userId");
        let classIdInput = document.querySelector("#classId");
        let submit = document.querySelector("#submit");
        submit.onclick = function() {
            $.ajax({
                type: 'post',
                url: 'homework2',
                data: JSON.stringify({
                    userId: userIdInput.value,
                    classId: classIdInput.value
                }),
                contentType: 'application/json; utf8',
                success: function(body) {
                    console.log(body);
                }
            });
        }
    </script>
</html>